package org.soc.timesheet.custom.domain.generators;

import java.io.Serializable;
import java.util.Properties;

import org.apache.commons.lang3.RandomStringUtils;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.id.Configurable;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.type.Type;

public class RandomStringIdGenerator implements IdentifierGenerator,
		Configurable {

	private int length;

	@Override
	public Serializable generate(SessionImplementor session, Object object)
			throws HibernateException {
		// TODO Auto-generated method stub

		return RandomStringUtils.randomAlphanumeric(length);
	}

	@Override
	public void configure(Type type, Properties params, Dialect d)
			throws MappingException {
		// TODO Auto-generated method stub
		length = Integer.parseInt(params.getProperty("length"));
	}

}
